$(function () {
    bindClickSubmit();
});
function formError(inputId, message) {
    const errorWindow = document.getElementById(inputId + '-error');
    errorWindow.textContent = message;
    errorWindow.style.display = 'block';
    setTimeout(function() {
        errorWindow.style.display = 'none';
    }, 3000);
}

function bindClickSubmit() {

    $('#btnSubmit').click(function () {
        $.ajax({
            url: "/auth/register/",
            method: "POST",
            dataType: "JSON",
            data: $('#regForm').serialize(),
            success: function (result) {
                if (result.status) {
                    location.href = result.data;
                } else {
                    $.each(result.errors, function (key, value) {
                        console.log(key)
                        console.log(value[0])
                        formError(key,value[0])
                    });
                }
                console.log(result.errors);
            }
        })
    })
}